package gui.MainFrame;

import gui.Paneli.Klubovi;
import gui.Paneli.ListaSportista;
import gui.Paneli.Sportisti;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Window;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;

import org.xml.sax.helpers.XMLFilterImpl;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.SystemColor;
import java.io.File;
import java.awt.Color;

public class OsnovniGui extends JFrame {

	
	
	
		
	//objekat za fajla kad se odabere
	public JFileChooser FILE = new JFileChooser();
	
	//Create and set up the content pane.
	public ListaSportista newContentPane = new ListaSportista();
	public Sportisti newContentPaneSP = new Sportisti();
	public Klubovi newContentPaneKlub = new Klubovi();
    
    
		
	public  OsnovniGui() {
		 
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1280, 800);
		setPreferredSize(new Dimension(1280,800));
		setTitle("test");		
		getContentPane().setLayout(new BorderLayout(10, 10));		
		getContentPane().setBackground(Color.LIGHT_GRAY);
		getContentPane().setForeground(Color.LIGHT_GRAY);
		
		
		
		
		//Dva Panela
		
      	final JPanel CenterPanel = new JPanel();      	
      	CenterPanel.setPreferredSize(new Dimension(800, 550));
      				      	            		
      	final JPanel SouthPanel = new JPanel();
      	SouthPanel.setBackground(Color.BLACK);
      	SouthPanel.setPreferredSize(new Dimension(800, 30));
      	
      	
      	getContentPane().add(CenterPanel, BorderLayout.CENTER);
      	getContentPane().add(SouthPanel, BorderLayout.SOUTH);
      	
      	
      	JLabel lblNewLabel = new JLabel("Made by Slobodan Toncevski  and Dragomir Simicevic");
      	lblNewLabel.setForeground(Color.WHITE);
      	lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
      	SouthPanel.add(lblNewLabel);
      	
        getContentPane();
        pack();
        setVisible(true);
		
		//File menu
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBackground(SystemColor.activeCaption);
		setJMenuBar(menuBar);		
		
		JMenu mnFile = new JMenu("File");
		mnFile.setMnemonic('F');		    
		menuBar.add(mnFile);
		
		JMenuItem mntmNew = new JMenuItem("New");
		
		//kreiranje novog fajla
		mntmNew.setAccelerator(KeyStroke.getKeyStroke("ctrl N"));
		mntmNew.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				FILE.addChoosableFileFilter(new FileFilter() {
					
					@Override
					public String getDescription() {
						// TODO Auto-generated method stub
						return null;
					}
					
					@Override
					public boolean accept(File f) {
						// TODO Auto-generated method stub
						  if (f.getName().toLowerCase().endsWith("xml"))
					      {
					        return true;
					      }
						  
						  return false;
					}
				});
				
				int returnVal = FILE.showDialog(null, "Create");
				
					
			}
		});
		mnFile.add(mntmNew);
		
		//Open File
		final JMenuItem OpenFile = new JMenuItem("Open File");
		OpenFile.setAccelerator(KeyStroke.getKeyStroke("ctrl O"));
		OpenFile.addActionListener(new ActionListener() {
			
			//da se otvori novi file chooser
			public void actionPerformed(ActionEvent e) {
				
				  //Handle open button action.		    		       
				   if (e.getSource() == OpenFile) {
					   	
					   	int returnVal = FILE.showOpenDialog(null);
					   	
					    if (returnVal == JFileChooser.APPROVE_OPTION) {
					    	getContentPane().removeAll();
					    	getContentPane().add(newContentPane);
					    	getContentPane().revalidate();
				            
				        } else {
				            //AKO KLIKUJE NEKA DRUGA OPCIJA
//				        	newContentPane = new ListaSportista();
//					    	frame.add(newContentPane);
				        }
				   }
			   
				
			}
		});
		mnFile.add(OpenFile);
		
		JMenuItem Save = new JMenuItem("Save");
		Save.setAccelerator(KeyStroke.getKeyStroke("ctrl N"));
		mnFile.add(Save);
		
		JMenuItem Print = new JMenuItem("Print");
		Print.setAccelerator(KeyStroke.getKeyStroke("ctrl P"));
		mnFile.add(Print);
		
		JMenuItem Close = new JMenuItem("Close");
		Close.setAccelerator(KeyStroke.getKeyStroke("ctrl W"));
		mnFile.add(Close);
		
		JMenuItem Exit = new JMenuItem("Exit");
		Exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		mnFile.add(Exit);
		
		//prvo dugme u menu
		JMenu mnDodavanjeUBazu = new JMenu("Dodavanje u Bazu");
		menuBar.add(mnDodavanjeUBazu);
		
		//Dodavanje sportista u bazu menu dugme
		
		JMenuItem DodajSportiste = new JMenuItem("Dodaj Sportiste");
		DodajSportiste.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				//kod za poziv  prozora sportisti
				getContentPane().removeAll();
				getContentPane().add(CenterPanel.add(newContentPaneSP));				
				getContentPane().revalidate();
				
			}
		});
		mnDodavanjeUBazu.add(DodajSportiste);
		
		//Dodavanje kluba u bazu menu dugme
		JMenuItem DodajKlub = new JMenuItem("Dodaj Klub");
		DodajKlub.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//kod za poziv KlubGui
				getContentPane().removeAll();
				getContentPane().add(CenterPanel.add(newContentPaneKlub));				
				getContentPane().revalidate();
			}
		});
		mnDodavanjeUBazu.add(DodajKlub);
		
		//Izvoz menu
		JMenu Izvoz = new JMenu("Izvoz");
		menuBar.add(Izvoz);
		
		JMenuItem mntmUPdf = new JMenuItem("u PDF");
		Izvoz.add(mntmUPdf);
		
		JMenuItem mntmUWord = new JMenuItem("u Word");
		Izvoz.add(mntmUWord);
		
		JMenuItem mntmUExel = new JMenuItem("u Exel");
		Izvoz.add(mntmUExel);
		
		//Pomoc menu
		JMenu Pomoc = new JMenu("Pomoc");
		menuBar.add(Pomoc);
		
		JMenuItem Dokumentacija = new JMenuItem("Dokumentacija");
		Pomoc.add(Dokumentacija);
		
		JMenuItem UpdateujProgram = new JMenuItem("Update-uj program");
		Pomoc.add(UpdateujProgram);
		
		JMenuItem OProgramu = new JMenuItem("O Programu");
		Pomoc.add(OProgramu);
	}
	
	
}


	

	 
